package com.tn.service.voice;

import com.alibaba.fastjson.JSON;
import com.tn.mqtt.MQTTConnect;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName SendVoiceDataMQ
 * @Description TODO
 * @Author Yezhongzhu
 * @Date 2022/3/2 16:34
 * @Version v1.0
 **/
@Component
@Slf4j
public class SendVoiceDataMQ {
    private final static String send_topic = "/jt808/voicetext";
    @Autowired
    private MQTTConnect mqttConnect;

    public void sendVoiceTextData(String tagId,String text){
        log.info("sendVoiceTextData location tagId:{},text:{}",tagId,text);
        try {
            Map<String,String> map = new HashMap<>();
            map.put("tagId",tagId);
            map.put("text",text);
            mqttConnect.pub(send_topic, JSON.toJSONString(map));
        } catch (MqttException e) {
            log.error("SendVoiceDataMQ sendVoiceTextData error:{}",e.getMessage());
        }
    }
}
